﻿using MediatR;
using W.Warehouse.Api.Application.Command.AllocationCommand;
using W.Warehouse.Api.Application.Command.MoveCommand;
using W.Warehouse.Repository.Interface;

namespace W.Warehouse.Api.Application.CommandHandlder.MoveCommandHadler
{
    public class MOVEAuditCommandHandler: IRequestHandler<MoveAuditCommand, int>
    {
        private readonly IMoveTheLibraryRepository moveTheLibraryRepository;
        public MOVEAuditCommandHandler(IMoveTheLibraryRepository moveTheLibraryRepository)
        {
            this.moveTheLibraryRepository = moveTheLibraryRepository;
        }

        public async Task<int> Handle(MoveAuditCommand request, CancellationToken cancellationToken)
        {
            var list = await moveTheLibraryRepository.GetAllAsync();
            var plist=list.Where(x=>x.MoveTheLibraryId==request.MoveTheLibraryId).FirstOrDefault();
            if (plist!=null)
            {
                plist.ExaminePeople = request.ExaminePeople;
                plist.ExamineTime=DateTime.Now;
                plist.AuditStatus = request.AllocationStatus;
            }
            return await moveTheLibraryRepository.UpdateAsync(plist);
        }
    }
}
